#include <iostream>
#include <queue>
#include <vector>

using namespace std;
const int N = 10010;
vector<int> edges[N];
int in[N], f[N];
queue<int> q;
int len[N];
int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int b, a;
		cin >> b >> len[i];
		while (cin >> a, a)
		{
			edges[a].push_back(b);
			in[b]++;
		}
	}
	for (int i = 1; i <= n; i++)
	{
		if (in[i] == 0) q.push(i);
	}
	int ret = 0;

	while (q.size())
	{
		auto x = q.front(); q.pop();
		f[x] += len[x];
		ret = max(ret, f[x]);
		for (auto y : edges[x])
		{
			f[y] = max(f[y], f[x]);
			in[y]--;
			if (in[y] == 0) q.push(y);
		}
	}
	cout << ret << endl;

	return 0;
}